import request from '@/utils/request'

const startUrl = '/activity'

/**
 * 申请活动
 * @param userStore
 * @param activityName 活动名
 * @param description 活动描述
 * @param maxNum 最大人数
 * @param expirationTime 过期时间
 * @param type 活动类型
 */
export const applyForActivity = (userStore, activityName, description, maxNum, expirationTime, type) =>
    request.post(startUrl + '/apply', {activityName, description, maxNum, expirationTime, type}, {
        headers: {
            'User-Token': userStore.$state.jwtEntity.jwt,
            'User-Secret-Key': userStore.$state.jwtEntity.signKeyStr
        }
    })

/**
 * 分页获取活动信息
 * @param userStore
 * @param current
 * @param size
 * @param activityName
 * @param maxNum
 * @param applicant
 * @param type
 * @param reviewer
 * @param activityStatus
 * @param university
 */
export const listUserPageActivity = (userStore, current, size, activityName, maxNum, applicant, type, reviewer, activityStatus, university) =>
    request.post(startUrl + '/page', {
        current,
        size,
        activityName,
        maxNum,
        applicant,
        type,
        reviewer,
        activityStatus,
        university
    }, {
        headers: {
            'User-Token': userStore.$state.jwtEntity.jwt,
            'User-Secret-Key': userStore.$state.jwtEntity.signKeyStr
        }
    })

/**
 * 获取单个活动信息
 * @param userStore
 * @param activityId
 */
export const oneActivity = (userStore, activityId) =>
    request.get(startUrl + '/detail',{
        params: {
            'activity_id': activityId,
        },
        headers: {
            'User-Token': userStore.$state.jwtEntity.jwt,
            'User-Secret-Key': userStore.$state.jwtEntity.signKeyStr
        }
    })

/**
 *
 * @param userStore
 * @param size
 * @param searchValue
 * @param current
 */
export const listPageActivityData = (userStore, size,searchValue, current) =>
    request.get(startUrl + '/history/data',{
        params: {
            'size': size,
            'current': current,
            'search_value': searchValue
        },
        headers: {
            'User-Token': userStore.$state.jwtEntity.jwt,
            'User-Secret-Key': userStore.$state.jwtEntity.signKeyStr
        }
    })

/**
 * 提交个人评分
 * @param userStore
 * @param activityId
 * @param grade
 * @param comment
 */
export const submitGrade = (userStore, activityId, grade, comment) =>
    request.get(startUrl + '/grade/self/submit',{
        params: {
            'activity_id': activityId,
            'grade': grade,
            'comment': comment,
        },
        headers: {
            'User-Token': userStore.$state.jwtEntity.jwt,
            'User-Secret-Key': userStore.$state.jwtEntity.signKeyStr
        }
    })

/**
 * 获取评分
 * @param userStore
 * @param activityId
 */
export const getGrade = (userStore, activityId) =>
    request.get(startUrl + '/grade/self/get',{
        params: {
            'activity_id': activityId,
        },
        headers: {
            'User-Token': userStore.$state.jwtEntity.jwt,
            'User-Secret-Key': userStore.$state.jwtEntity.signKeyStr
        }
    })


/**
 * 更新个人评分
 * @param userStore
 * @param activityId
 * @param grade
 * @param comment
 */
export const updateSelfGrade = (userStore, activityId, grade, comment) =>
    request.get(startUrl + '/grade/self/update',{
        params: {
            'activity_id': activityId,
            'grade': grade,
            'comment': comment,
        },
        headers: {
            'User-Token': userStore.$state.jwtEntity.jwt,
            'User-Secret-Key': userStore.$state.jwtEntity.signKeyStr
        }
    })
/**
 * 分页获取整个活动的评分
 * @param userStore
 * @param current
 * @param pageSize
 * @param activityId
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const pageAllGrade = (userStore, current, pageSize, activityId) =>
    request.get(startUrl + '/grade/all/page',{
        params: {
            'current': current,
            'page_size': pageSize,
            'activity_id': activityId

        },
        headers: {
            'User-Token': userStore.$state.jwtEntity.jwt,
            'User-Secret-Key': userStore.$state.jwtEntity.signKeyStr
        }
    })

/**
 * 获取评论数量
 * @param userStore
 * @param activityId
 */
export const getCommentCount = (userStore, activityId) =>
    request.get(startUrl + '/grade/comment/count',{
        params: {
            'activity_id': activityId

        },
        headers: {
            'User-Token': userStore.$state.jwtEntity.jwt,
            'User-Secret-Key': userStore.$state.jwtEntity.signKeyStr
        }
    })